@@ -2,8 +2,11 @@ package com.controller;

import com.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@@ -14,28 +17,57 @@ public class UserController {
    String userId = request.getParameter("userId");
        System.out.println("userId = " + userId);
}

@RequestMapping("/getUserNameAndId")
public void getUserNameAndId(String username,Integer id) {
    public void getUserNameAndId(String username, Integer id) {
        System.out.println("username = " + username + ",id = " + id);
    }

    @RequestMapping("/getUserName")
    public void getUserName(
            @RequestParam(value = "name", required = false, defaultValue = "itheima") String username){
        System.out.println("username = " + username);
        @RequestParam(value = "name", required = false, defaultValue = "itheima") String username) {
            System.out.println("username = " + username);
        }

        @RequestMapping("/registerUser")
        public void registerUser(User user) {
            String name = user.getName();
            String password = user.getPassword();
            System.out.println("name = " + name);
            System.out.println("password = " + password);
            String name = user.getName();
            String password = user.getPassword();
            System.out.println("name = " + name);
            System.out.println("password = " + password);

        }

        @RequestMapping("/findOrderWithUser")
        public void findOrderWithUser(User user){
            public void findOrderWithUser(User user) {
                String username = user.getName();
                String OrderId = user.getOrder().getOrderId();
                System.out.println("username = " + username + ",OrderId = " + OrderId);
            }

            @RequestMapping("/showPageByRequest")
            public String showPageByRequest(HttpServletRequest request) {
                request.setAttribute("username", "理想");
                return "register";

            }

            @RequestMapping("/showPageByModel")
            public String showPageByModel(Model model) {
                model.addAttribute("username", "model");
                User user = new User();
                user.setPassword("123456");
                model.addAttribute("user", user);
                return "register";
            }
            @RequestMapping("/showModelView")
            public ModelAndView showModelView() {
                ModelAndView modelAndView = new ModelAndView();
                modelAndView.addObject("username", "黑马");
                User user = new User();
                user.setPassword("987654321");
                modelAndView.addObject("user", user);
                modelAndView.setViewName("register");
                return modelAndView;
            }
        }